<template>
  <mask-content :isShow="isShow"
                :mask-closable="maskClosable"
                @close="handleClose">
    <view class="modal pi-content"
          :style="{width: width}"
          @tap.stop>
      <view class="title">
        <text>{{title}}</text>
        <view class="pi-icon-close close"
              @tap.stop="handleClose"></view>
      </view>
      <view v-if="content"
            class="content">{{content}}</view>
      <slot v-else>
        <!-- 当content传入的时候,以content为主,适合特殊样式 -->
      </slot>
      <view class="btns">
        <button v-for="(btn, index) in btns"
                :key="index"
                :style="btn.style"
                @tap="handleBtnClick(index)">{{btn.text}}</button>
      </view>
    </view>
  </mask-content>
</template>

<script>
import MaskContent from '@/src/PiUI-basic/components/mask-content.vue'


export default {
  components: {
    MaskContent
  },
  props: {
    // 是否显示
    isShow: {
      required: false,
      type: Boolean,
      default: false
    },
    // 点击蒙层是否允许关闭
    maskClosable: {
      required: false,
      type: Boolean,
      default: true
    },
    title: {
      type: String,
      default () {
        return '提示'
      }
    },
    content: {
      type: String,
    },
    btns: {
      type: Array,
      default () {
        return [
          {
            text: '取消',
            style: 'color: rgba(24, 144, 255, 1);'
          },
          {
            text: '确定',
            style: 'color: #ffffff;background: linear-gradient(90deg, rgba(53, 195, 255, 1) 0%, rgba(24, 144, 255, 1) 100%);'
          }
        ]
      }
    },
    width: {
      type: [String, Number],
      default () {
        return '622rpx'
      }
    }
  },
  data () {
    return {}
  },
  computed: {

  },

  methods: {
    handleBtnClick (index) {
      const btn = this.btns[index]
      this.$emit('btn-click', btn)
    },
    handleClose () {
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>
.modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: 100%;
  max-height: 100%;
  transform: translate(-50%, -50%);
  background-color: #ffffff;
  border-radius: 8px;
  .title {
    position: relative;
    width: 100%;
    font-size: 36rpx;
    font-weight: 500;
    text-align: center;
    margin-bottom: 24rpx;
    .close {
      position: absolute;
      top: 50%;
      right: 0;
      font-size: 44rpx;
      font-weight: 500;
      color: #999999;
      transform: translateY(-50%);
    }
  }
  .content {
    font-size: 32rpx;
    color: #666666;
    line-height: 1.5;
    text-indent: 2em;
    padding: 20rpx 0;
  }
  .btns {
    display: flex;
    width: 100%;
    align-items: center;
    margin-top: 24rpx;
    button {
      font-size: 32rpx;
      font-weight: 500;
      flex: 1;
      height: 88rpx;
      background: rgba(231, 242, 255, 1);
      border-radius: 8rpx;
    }
    button:first-child {
      margin-right: 24rpx;
      color: rgba(24, 144, 255, 1);
    }
    button:last-child {
      background: linear-gradient(90deg, rgba(53, 195, 255, 1) 0%, rgba(24, 144, 255, 1) 100%);
      color: rgba(255, 255, 255, 1);
    }
  }
}
</style>
